package com.jiantong.work.impl.service;

import com.google.common.base.Throwables;
import com.jiantong.work.impl.manager.VaccinePurchaseRecordManager;
import com.jiantong.work.model.VaccinePurchaseRecord;
import com.jiantong.work.service.VaccinePurchaseRecordWriteService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by maowenjie on 2017/4/17.
 */
@Slf4j
@Service
@RpcProvider
public class VaccinePurchaseRecordWriteServiceImpl implements VaccinePurchaseRecordWriteService {

    private final VaccinePurchaseRecordManager vaccinePurchaseRecordManager;

    @Autowired
    public VaccinePurchaseRecordWriteServiceImpl(VaccinePurchaseRecordManager vaccinePurchaseRecordManager) {
        this.vaccinePurchaseRecordManager = vaccinePurchaseRecordManager;
    }

    @Override
    public Response<Map<String, Object>> createVaccinePurchaseRecord(VaccinePurchaseRecord vaccinePurchaseRecord, Integer toStatus) {
        try{
            return Response.ok(vaccinePurchaseRecordManager.createVaccinePurchaseRecord(vaccinePurchaseRecord,toStatus));
        }catch (Exception e){
            log.error("failed to create vaccinePurchaseRecord error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("vaccinePurchaseRecord.create.failed");
        }
    }

    @Override
    public Response<Map<String, Object>> updateVaccinePurchaseRecord(VaccinePurchaseRecord vaccinePurchaseRecord, Integer toStatus) {
        try{
            return Response.ok(vaccinePurchaseRecordManager.updateVaccinePurchaseRecord(vaccinePurchaseRecord,toStatus));
        }catch (Exception e){
            log.error("failed to update vaccinePurchaseRecord error :{}", Throwables.getStackTraceAsString(e));
            return Response.fail("vaccinePurchaseRecord.update.failed");
        }
    }

    @Override
    public Boolean update(VaccinePurchaseRecord vaccinePurchaseRecord) {
        return vaccinePurchaseRecordManager.update(vaccinePurchaseRecord);
    }
}
